Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lexical scope in loose mode #1351

Merged
merged 2 commits into from
Oct 21, 2021
Merged

Support lexical scope in loose mode #1351

merged 2 commits into from
Oct 21, 2021

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Oct 21, 2021

This allows you to pass lexically scoped values into templates even when those templates are not in strict mode. The whole system is already designed to make this work correctly, all that is required is to not actively stop it from working.

This use case is hugely useful as a compile target for embroider because embroider already does built-time resolution of components and helpers in existing (non-strict) templates. Today our compiler output does:

import a0 from './path/to/some-component';
import { precompileTemplate } from '@ember/template-compilation';
window.define('your-app/components/some-component', function() { return a0 });
export default precompileTemplate("<SomeComponent />");

With this feature it can become:

import SomeComponent from './path/to/some-component';
import { precompileTemplate } from '@ember/template-compilation';
export default precompileTemplate("<SomeComponent />", { scope: () => ({ SomeComponent }), strictMode: false });

which means we skip over a large amount of runtime registration and lookup.

ef4 added 2 commits October 21, 2021 16:37
This refactors defineComponent's arguments so that you can override `definition` and `strictMode` independently.
@ef4 ef4 marked this pull request as ready for review October 21, 2021 20:43
@rwjblue rwjblue merged commit b1a69ad into master Oct 21, 2021
@rwjblue rwjblue deleted the loose-lexical-support branch October 21, 2021 20:52
rwjblue added a commit to emberjs/ember.js that referenced this pull request Oct 21, 2021
rwjblue added a commit to emberjs/ember.js that referenced this pull request Oct 21, 2021
@ef4
Copy link
Contributor Author

ef4 commented Oct 22, 2021

So it turns out the test coverage here is extremely unrealistic and this is insufficient to make it work for actual precompiled templates. Followup PR coming.

ef4 added a commit that referenced this pull request Oct 22, 2021
#1351 was incomplete, and the test suite didn't make that clear because it doesn't exercise real template precompilation.

This time I've manually tested end-to-end in a real app (alongside ember canary).
rwjblue pushed a commit that referenced this pull request Oct 22, 2021
#1351 was incomplete, and the test suite didn't make that clear because it doesn't exercise real template precompilation.

This time I've manually tested end-to-end in a real app (alongside ember canary).

(cherry picked from commit 978c924)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants